#include <event_manager.h>
#include <nodelevel_aggregator.h>


// TLS Event

struct evt_properties tls_event_ppt_witharg;
struct evt_properties global_event_ppt_witharg;



delegate_lock_p globevent_actionlock = new_delegate_lock();

evthdl globevent_hdl;
evthdl tlsevent_hdl;


#define EVT_GLOBEVENT(X) EVT_PARAM(X)
#define EVT_TLSEVENT(X) EVT_PARAM(X)

bool global_state_indicator( void * arg ) {
    return true;
}


static int counter = 0;

void globevent_action( void * arg ) {
    counter ++;
}


int main () {
        tls_event_ppt_witharg.evtp_has_argument = true;
        tls_event_ppt_witharg.evtp_is_state_event = false;
        tls_event_ppt_witharg.evtp_is_thread_local = true;
        tls_event_ppt_witharg.evtp_name = "TLS_EVT";
        tls_event_ppt_witharg.lock = NULL; // No lock : tls.

        global_event_ppt_witharg.evtp_has_argument = true;
        global_event_ppt_witharg.evtp_is_state_event = true;
        global_event_ppt_witharg.state_indicator = global_state_indicator;
        global_event_ppt_witharg.lock = globevent_actionlock;

        globevent_hdl = init_event(&global_event_ppt_witharg);
        tlsevent_hdl = init_event(&tls_event_ppt_witharg);

#pragma omp parallel
 {
        action_for_events( globevent_action, NULL, EVT_GLOBEVENT(NULL), EVT_TLSEVENT(NULL));


        signal_event( EVT_TLSEVENT(NULL) );

 }
        printf( "Counter : %d \n" , counter);

}
